package net.citrite.android;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.logging.Logger;

public class SummaryReport {
    private Date startTime = new Date(System.currentTimeMillis());
    private static Logger detailLog = Logger.getLogger("report.csv");
    private static Logger summaryLog = Logger.getLogger("summary.csv");
    private int items = 0;
    public SummaryReport() {

    }
    public void parse(List<MeasureReport> reportList) {
        List<String> files = new ArrayList<>();
        int errors = 0;
        int warnings = 0;

        for (MeasureReport report : reportList) {
            detailLog.info(report.toString());
            if (!files.contains(report.getFile())) {
                files.add(report.getFile());
            }
            if (report.getSeverity().equals(Severity.ERROR)) {
                errors ++;
            } else {
                warnings ++;
            }
        }

        Date endTime = new Date(System.currentTimeMillis());
        String start = new SimpleDateFormat("HH/mm/ss.SSS").format(startTime);
        String end = new SimpleDateFormat("HH/mm/ss.SSS").format(endTime);
        //String ret = String.format("%s\t%d\t%d\t%d\t%s\t%s\t%s\t%s", files.size(), errors, warnings, items, start, end, "TruncationDetector4Android", "1.0");
        String ret = String.format("%s,%d,%d,%d,%s,%s,%s,%s", files.size(), errors, warnings, items, start, end, "TruncationDetector4Android", "1.0");
        summaryLog.info(ret);
    }

    public void inc() {
        items ++;
    }
}
